function [Seg_info_table,aha_info, Thickness_figure, bp_Area]=readsingleroiinfo( file_dir, image_name, Obj_slice_num,center_pos,t1_t2,ROI_name)

% Case = 'T2map';
% image_name = 'Yousheng_Chen_WIP_HiRes-NAV-4T2MapTE_CLEAR_11_1_t2map_R90';    % no suffix
% file_dir =  'D:\dingDATA\segmentation  result\ROI_Zhou\20121227 MyoT2 NV009\';
ROI_dir = [file_dir ROI_name] ;
if(~isdir(ROI_dir))
    disp('please input correct ROI path');
    return;
end
image_path = [file_dir image_name '.mat'];
load(image_path);
IM = T1(:,:,:,t1_t2);
roifiles = dir([ROI_dir filesep '*.mat']);
file_length = length( roifiles );
ROI_info_tables = {};
ROI_info_tables_ix = 1;
start_Si = 100;
end_Si = 0;
for file_ix = 1:file_length
    file_name = roifiles(file_ix,1).name;
    if( ~isempty( regexpi(file_name,'^S\d\d.mat')) || ~isempty(regexpi(file_name,'^S\d.mat')))
        load([ ROI_dir filesep file_name]);
        str_cell = regexpi(file_name,'[\d][\d]{0,}','match') ;
        slice_num = str2num(str_cell{1,1});
        if(  slice_num == Obj_slice_num )
            roi_info.roi_info_table = ROI_info_table;
            roi_info.slice_num = slice_num ;
            ROI_info_tables{1,1} = roi_info;
            %load aha info 
            try 
                load([ ROI_dir filesep 'AHA' num2str(slice_num) '.mat']);
                aha_info = AHAInfo;
            catch
                aha_info = [];
            end
                
        end
    end
end

slice_ix = 1;
roi_info_table = ROI_info_tables{1,slice_ix}.roi_info_table;
slice_i = ROI_info_tables{1,slice_ix}.slice_num;
inImg = IM(:,:,slice_i,1) ;
inImg = double(inImg);

Debug_disp = 0;
local_im = inImg;
Image_M = size(inImg,1);
Image_N = size(inImg,2);
%parameters_case = 'T2map';
Seg_info_table = struct( ...
    'SEG_Si',[],...                 %01
    'SEG_Epi_Area', [], ...         %02
	'SEG_Epi_R_mean', [], ...       %03
    'SEG_Epi_R_max', [], ...        %04
	'SEG_Epi_R_min', [], ...        %05
    'SEG_Epi_R_std', [], ...        %06
    'SEG_Endo_Area', [], ...        %07
	'SEG_Endo_R_mean', [], ...      %08
    'SEG_Endo_R_max', [], ...       %09
    'SEG_Endo_R_min',[], ...        %010
    'SEG_Endo_R_std',[], ...        %011
    'SEG_Endo_T1_mean',[], ...      %012
    'SEG_Endo_T1_max',[], ...       %013
    'SEG_Endo_T1_min', [], ...     %014
    'SEG_Endo_T1_std', [], ...      %015
    'SEG_Endo_T2_mean',[], ...      %012
    'SEG_Endo_T2_max',[], ...       %013
    'SEG_Endo_T2_min', [], ...     %014
    'SEG_Endo_T2_std', [], ...      %015
    'SEG_Thickness_max', [], ...    %016
    'SEG_Thickness_min', [], ...    %017
    'SEG_Thickness_mean', [], ...   %018
    'SEG_Thickness_std', []);       %019

[M N] = size( roi_info_table );
if( M == 2)
%got epi_ and endo_ info
if( max(roi_info_table(1,1).ROI_x_coordinates ) >  max(roi_info_table(2,1).ROI_x_coordinates ))
    EPI = 1;
    ENDO = 2;
else 
    EPI = 2;
    ENDO = 1;   
end

EPI_x =  roi_info_table(EPI,1).ROI_x_coordinates; % - floor( min_EPI_x );
EPI_y =  roi_info_table(EPI,1).ROI_y_coordinates ;% - floor( min_EPI_y );
IM_EPI=local_im;
[EPI_mesh_x,EPI_mesh_y] = meshgrid([1:size(IM_EPI,2)],[1:size(IM_EPI,1)]);
EPI_RR = inpolygon(EPI_mesh_x,EPI_mesh_y,EPI_x,EPI_y);
[EPI_i,EPI_j] = find(EPI_RR);
mean_EPI_i = mean( EPI_i );
mean_EPI_j = mean( EPI_j );
if(Debug_disp)
	f = figure;
	imagesc(IM_EPI);
	axis equal; 
	hold on;
    title('Press Any Key To Continue');
 	plot(EPI_j,EPI_i,'r.');
	plot(EPI_x,EPI_y,'r-.')
	colormap(get(f, 'Colormap'));
end
IM_EPI_ex =zeros(size(IM_EPI));
IM_EPI_ex(sub2ind(size(IM_EPI),EPI_i,EPI_j)) = 1;
if(Debug_disp)
	figure,
	imagesc(IM_EPI_ex);
	axis equal; 
	hold on;
    title('Press Any Key To Continue');
 	plot(EPI_j,EPI_i,'r.');
	plot(EPI_x,EPI_y,'r-.')
end
%remove NaN type 
IM_EPI_ex(isnan( IM_EPI_ex)) = 0;
epi_area = sum(sum(IM_EPI_ex ));

ENDO_x =  roi_info_table(ENDO,1).ROI_x_coordinates ;%- floor( min_ENDO_x );
ENDO_y =  roi_info_table(ENDO,1).ROI_y_coordinates ;%- floor( min_ENDO_y );
IM_ENDO= local_im; %((floor(min_ENDO_y):ceil(max_ENDO_y)),floor(min_ENDO_x):ceil(max_ENDO_x));
[ENDO_mesh_x,ENDO_mesh_y] = meshgrid([1:size(IM_ENDO,2)],[1:size(IM_ENDO,1)]);
ENDO_RR = inpolygon(ENDO_mesh_x,ENDO_mesh_y,ENDO_x,ENDO_y);
[ENDO_i,ENDO_j] = find(ENDO_RR);
mean_ENDO_i = mean( ENDO_i );
mean_ENDO_j = mean( ENDO_j );
if(Debug_disp)
	f = figure;
	imagesc(IM_ENDO);
	axis equal; 
	hold on;
    title('Press Any Key To Continue');
 	plot(ENDO_j,ENDO_i,'r.');
	plot(ENDO_x,ENDO_y,'r-.')
	colormap(get(f, 'Colormap'));
    hold off;
end
ex_ENDO_Im = ones( size( IM_EPI_ex ));
ex_ENDO_Im(sub2ind(size(ex_ENDO_Im),ENDO_i,ENDO_j)) = 0;

inv_ex_ENDO_Im = zeros( size( IM_EPI_ex ));
inv_ex_ENDO_Im(sub2ind(size(ex_ENDO_Im),ENDO_i,ENDO_j)) = 1;
endo_area  = sum(sum(inv_ex_ENDO_Im));
if(Debug_disp)
	f = figure;
	imagesc(ex_ENDO_Im);
	axis equal; 
    hold on;
    title('Press Any Key To Continue');
 	plot(ENDO_j,ENDO_i,'r.');
	plot(ENDO_x,ENDO_y,'r-.')
	colormap(get(f, 'Colormap'));
    hold off;
end
EPI_ENDO_IM_one = ex_ENDO_Im.*IM_EPI_ex;
if(Debug_disp)
	f = figure;
    hold on;
	imagesc(EPI_ENDO_IM_one);
	axis equal; 
    title('Press Any Key To Continue');
 	plot(ENDO_j,ENDO_i,'r.');
	plot(ENDO_x,ENDO_y,'r-.')
	colormap(get(f, 'Colormap'));
    hold off;
end

Thickness_figure = EPI_ENDO_IM_one.*inImg;
%generate a common radius arr 
if( isempty(center_pos))
    center_y = mean( EPI_y );
    center_x = mean( EPI_x );
else
    center_y = center_pos(2,1);
    center_x = center_pos(1,1);
end
common_scan_rs = [ center_y ...
center_x ...
(Image_M - center_y -1) ...
(Image_N - center_x -1) ];
Common_scan_r = min(common_scan_rs );
Sample_pt_along_circle = 360 ;
delta_theta = 2*pi/Sample_pt_along_circle;
Common_theta_arr =[0:delta_theta:2*pi-delta_theta];
delta_r = 0.5;
Common_R_arr = delta_r:delta_r:Common_scan_r;
Common_X_axis_arr  = Common_R_arr'*sin(Common_theta_arr)+center_x ;
Common_Y_axis_arr  = Common_R_arr'*cos(Common_theta_arr)+center_y ;
affline_len = size(Common_Y_axis_arr,2 );
delta_line_len = length(Common_R_arr );
epi_radius_arr = zeros(1,affline_len);
endo_radius_arr = zeros(1,affline_len);
epi_x  = zeros(1,affline_len);
epi_y  = zeros(1,affline_len);
endo_x  = zeros(1,affline_len);
endo_y  = zeros(1,affline_len);
bp_x = zeros(1,affline_len);
bp_y = zeros(1,affline_len);
for line_ix = 1 : affline_len
    for delta_ix = 1 : delta_line_len
          line_contrast(1,delta_ix) = EPI_ENDO_IM_one(ceil(Common_Y_axis_arr(delta_ix,line_ix)),ceil(Common_X_axis_arr(delta_ix,line_ix)));
    end
    [ Tag_st_pos,Tag_end_pos ] = tracedatsegment( line_contrast,1,0 );
    if(~isempty(Tag_st_pos))
        epi_radius_arr(1,line_ix) =sqrt( ( Common_Y_axis_arr(Tag_end_pos(end,1),line_ix) - center_y ).^2+( Common_X_axis_arr(Tag_end_pos(end,1),line_ix) - center_x ).^2  );
        endo_radius_arr(1,line_ix) =sqrt( ( Common_Y_axis_arr(Tag_st_pos(1,1),line_ix) - center_y ).^2+( Common_X_axis_arr(Tag_st_pos(1,1),line_ix) - center_x ).^2  );
        epi_x(1,line_ix) = Common_X_axis_arr(Tag_end_pos(end,1),line_ix) ;
        epi_y(1,line_ix) = Common_Y_axis_arr(Tag_end_pos(end,1),line_ix) ;
        endo_x(1,line_ix) = Common_X_axis_arr(Tag_st_pos(1,1),line_ix);
        endo_y(1,line_ix) = Common_Y_axis_arr(Tag_st_pos(1,1),line_ix);
        
       
%         bp_x(1,line_ix) =   Common_X_axis_arr(fix(Tag_st_pos(1,1)/3),line_ix);
%         bp_y(1,line_ix) =   Common_Y_axis_arr(fix(Tag_st_pos(1,1)/3),line_ix);
        
    else
 
        if(line_ix>1)
            epi_x(1,line_ix) = epi_x(1,line_ix-1);
            epi_y(1,line_ix) = epi_y(1,line_ix-1) ;
            endo_x(1,line_ix) = endo_x(1,line_ix-1);
            endo_y(1,line_ix) = endo_y(1,line_ix-1);
%             bp_x(1,line_ix) = bp_x(1,line_ix-1);
%             bp_y(1,line_ix) = bp_y(1,line_ix-1);
        end
        epi_radius_arr(1,line_ix) = 0 ;
        endo_radius_arr(1,line_ix) = 0;
    end
end

EPI_ENDO_sampling_thickness =epi_radius_arr - endo_radius_arr ;
end

%Here, Part of blood pool are sampled
% bp_Im_mask = zeros( size( IM_EPI_ex ));
% [bp_mesh_x,bp_mesh_y] = meshgrid([1:size(bp_Im_mask,2)],[1:size(bp_Im_mask,1)]);
% bp_RR = inpolygon(bp_mesh_x,bp_mesh_y,fix(bp_x),fix(bp_y));
% [bp_i,bp_j] = find(bp_RR);
% bp_Im_mask(sub2ind(size(bp_Im_mask),bp_i,bp_j)) = 1;
% 
% bp_Area = bp_Im_mask.*inImg;
bp_Area = [];
%structure the ROI struct
Seg_info_table.EPI_x = epi_x ;
Seg_info_table.EPI_y = epi_y ;
Seg_info_table.ENDO_x = endo_x ;
Seg_info_table.ENDO_y = endo_y ;
Seg_info_table.SEG_Si = 0;
Seg_info_table.SEG_Epi_Area = epi_area; 
Seg_info_table.SEG_Epi_R_mean = epi_radius_arr;
Seg_info_table.SEG_Epi_R_max = center_y;
Seg_info_table.SEG_Epi_R_min = center_x;
Seg_info_table.SEG_Epi_R_std =[];
Seg_info_table.SEG_Endo_Area = endo_area;
Seg_info_table.SEG_Endo_R_mean = endo_radius_arr;
Seg_info_table.SEG_Endo_R_max = [];
Seg_info_table.SEG_Endo_R_min = [];
Seg_info_table.SEG_Endo_R_std = [];
Seg_info_table.SEG_Thickness_max = EPI_ENDO_sampling_thickness;
Seg_info_table.SEG_Thickness_min = [];
Seg_info_table.SEG_Thickness_mean = [];
Seg_info_table.SEG_Thickness_std = [];


end



